#include "DynamicArray.h"
#include <iostream>


DynamicArray::DynamicArray():size(10),len(0)//初始化列表
{
    this->a = new int[this->size];
}

DynamicArray::~DynamicArray()
{
    delete []this->a;
}

DynamicArray::DynamicArray(const DynamicArray &da)
{
    this->size = da.size;
    this->len = da.len;
    this->a = new int[this->size];
    for(int i = 0; i < this->len;i++)
    {
        this->a[i] = da.a[i];
    }
}

void DynamicArray::operator=(const DynamicArray &da)
{
    delete []this->a;
    this->size = da.size;
    this->len = da.len;
    this->a = new int[this->size];
    for(int i = 0; i < this->len;i++)
    {
        this->a[i] = da.a[i];
    }
}

void DynamicArray::InsterTail(int element)
{
    if(this->len >= this->size)
    {
        this->size *= 2;
        int *newP = new int[this->size];
        for(int i = 0; i < this->len;i++)
        {
            newP[i] = this->a[i];
        }
        delete []this->a;
        this->a = newP;
    }
    this->a[this->len++] = element;
}

void DynamicArray::show()
{
    std::cout<<"len : "<<len <<"size : "<<size<<std::endl;
    for(int i = 0; i < len; i++)
    {
        std::cout<<a[i]<<" ";
    }
    std::cout<<std::endl;
}
